package pl.smath.operation.basic;

import junit.framework.TestCase;
import pl.smath.expression.SumTerm;
import pl.smath.expression.Term;
import pl.smath.operation.BasicOp;
import pl.smath.parser.ExpressionParser;


public class AddTestCase extends TestCase {

	/** 
	 * Test data. Format:
	 * input => expected output 
	 */
	private static final String[][] testData = {
		{"2*3", "2*3"},
		{"2+3", "5"},
		{"2+3+14", "19"},
		{"3-4", "-1"},
		{"-3-4", "-7"},
		{"2-3+4", "3"},
		{"2+1-3+4", "4"},
		{"2.5+1-3+4", "4.5"},
		{"2-3--4", "3"},
		{"-x-x", "-2*x"},
		{"-x+x", "0"},
		{"x-x", "0"},
		{"x+x", "2*x"},
		{"x+3*x", "4*x"},
		{"x-x*3", "-2*x"},
		{"-3*x-x", "-4*x"},
		{"a*b+a*b", "2*a*b"},
		{"a*b+b*a", "2*a*b"},
		{"a+2*x-x-x", "a"},
		{"2*x+3*x", "5*x"},
		{"-2*x-3*y", "-2*x-3*y"},
		{"2*x^2+3*x^2", "5*x^2"},
		{"2*x+3*5*x", "2*x+3*5*x"},
		{"x^2+x^2", "2*x^2"},
		{"2*x^2+x^2", "3*x^2"},
		{"-x^2-3*x^2", "-4*x^2"}
	};
	
	
	public void testData() {
		ExpressionParser parser = new ExpressionParser();
		Term	input;
		Term	output;
		
		for(int i = 0; i < testData.length; i++){
		
			input = parser.parseText( testData[i][0] );
			if(input instanceof SumTerm){
				output = BasicOp.simplify( input );
			}
			else{
				output = input;
			}
			
			assertEquals("Input: " + testData[i][0], testData[i][1], output.toString());
		}
	}

}
